const api = require('../../utils/http.js');
const app = getApp();
const { $Toast } = require('../../dist/base/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  shareFriendCircle(cardUrl) {
    this.setData({
      painting: {
        width: 375,
        height: 660,
        clear: true,
        views: [{
          type: 'image',
          url: '../../pages/images/share_bg.png',
          top: 0,
          left: 53,
          width: 269,
          height: 398
        },
        {
          type: 'image',
          url: app.globalData.userInfo.avatarUrl,
          top: 45,
          left: 221,
          width: 55,
          height: 55,
          
        },
        {
          type: 'image',
          url: '../../pages/images/circle.png',
          top: 45,
          left: 221,
          width: 55,
          height: 55
        },
        {
          type: 'text',
          content: '校园帮帮',
          fontSize: 18,
          color: '#fff',
         
          textAlign: 'left',
          top: 332,
          left: 150,
          bolder: true
        },
        {
          type: 'text',
          content: '为同学提供校园服务',
          fontSize: 13,
          color: '#fff',
          textAlign: 'left',
          top: 358,
          left: 125,
          bolder: true
        },
        {
          type: 'image',
          url: cardUrl,
          top: 250,
          left: 150,
          width: 80,
          height: 80,
          textAlign: 'center'
        },



        ]
      }
    })
  },
  eventGetImage(event) {
    console.log(event)
    wx.hideLoading()
    const {
      tempFilePath,
      errMsg
    } = event.detail

    if (errMsg === 'canvasdrawer:ok') {
      console.log(tempFilePath)
      this.setData({
        shareImage: tempFilePath
      })
    }

  },
  eventSave() {
    wx.saveImageToPhotosAlbum({
      filePath: this.data.shareImage,
      success(res) {
        $Toast({
          content: '保存图片成功',
          type: 'success'
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(app.globalData.userInfo)
    wx.showLoading({
      title: '绘制分享图片中',
      mask: true
    })
    var uid = app.globalData.uid;
   // app.fetchApi('/ucenter/getUserInfo').then(e => {
      // console.log(e)
     // app.globalData.userInfo = e.data.data.row
    api.fetchApi('api/getQRcode', { uid, page:'pages/index/index' }).then(res => {
      if(res.data.code==1){
        var codeUrl=res.data.url;
        this.shareFriendCircle(codeUrl)
      }else{
        
        $Toast({
          content: '二维码生成失败',
          type: 'error'
        });
      }
     
      
      })
   // })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})